package com.kunbo.cn.controller.core.poundlist;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.kunbo.cn.service.core.poundlist.SalesPoundListService;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.BuildBean1;
import com.kunbo.cn.util.retu.CommonResult;
import com.kunbo.cn.util.retu.ResultBean;
import com.kunbo.cn.util.retu.ResultBean1;
/**
 * 销售磅单
 * @author  编写人:刘义
 * @date 时间:2019年3月18日上午11:24:36
 */
@RestController
@RequestMapping("/spl")
public class SalesPoundListController {
	@Autowired
	private SalesPoundListService splService;
	
	@RequestMapping("/add")
	public CommonResult add(String type,String jsonstr) {
		if(StringUtils.isBlank(type)) {
			return new CommonResult(false, "类型不可为空", null);
		}else if(StringUtils.isBlank(jsonstr)) {
			return new CommonResult(false, "json串为空", null);
		}
		try {
			splService.save(type,jsonstr);
			return new CommonResult(true, "磅单新增成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return new CommonResult(false, "异常导致新增磅单失败", null);
		}
	}
	
	@RequestMapping(value="/update",method=RequestMethod.POST)
	public CommonResult update(String type,String jsonstr) {
		if(StringUtils.isBlank(type)) {
			return new CommonResult(false, "类型不可为空", null);
		}else if(StringUtils.isBlank(jsonstr)) {
			return new CommonResult(false, "json串为空", null);
		}
		try {
			Map<String,Object> rm = splService.update(type,jsonstr);
			return new CommonResult(true, "称重完成，请下磅，"+rm.get("msg").toString(), rm.get("salePound"));
		} catch (Exception e) {
			e.printStackTrace();
			return new CommonResult(false, "异常导致新增磅单失败", null);
			
		}

	}
	
	
	
	/**
	 * 
	 * <p>Title: update</p>
	 * <p>Description:销售磅单补增 </p>
	 * @param type
	 * @param jsonstr
	 * @return
	 */
	@RequestMapping(value="/salementaryIncrease",method=RequestMethod.POST)
	public CommonResult salementaryIncrease(String jsonstr) {
		
		if(StringUtils.isBlank(jsonstr)) {
			return new CommonResult(false, "json串为空", null);
		}
		try {
			splService.salementaryIncrease(jsonstr);
			return new CommonResult(true, "磅单更新成功", null);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return new CommonResult(false, "异常导致新增磅单失败", null);
			
		}

	}
	
	
	/**
	 * 选销售单号
	 * @param startTime  开始时间
	 * @param endTime    结束时间
	 * @param supplier   供应商
	 * @param materialType  物料类型
	 * @param material   物料
	 * @param orderCode  订单号
	 * @param page       当前页
	 * @param pageSize   当前页数据长度
	 * @return
	 */
	@PostMapping("/selsaleOrderCode.do")
	public CommonResult selsaleOrderCode(
			@RequestParam String startTime,
			@RequestParam String endTime,
			@RequestParam String supplier,
			@RequestParam String material,
			@RequestParam String orderCode,
			@RequestParam Integer page,
			@RequestParam Integer pageSize
			) {
		return splService.selsaleOrderCode(startTime,endTime,supplier,material,orderCode,page,pageSize);
	}
	
	
	
	/**
	 * 级联显示采购补增单其他信息
	 * @param orderCode  发货单号
	 * @return
	 */
	@PostMapping("/showOhterMes.do")
	public CommonResult showOhterMes(@RequestParam String orderCode) {
		return splService.showOhterMes(orderCode);
	}
	
	
	
	
	
	
	
	
	@PostMapping("/SalePoundList")
	public CommonResult SalePoundList(
			@RequestParam String start_time,
			@RequestParam String end_time,
			@RequestParam String shippingUnit,//发货单位
			@RequestParam String xsPoundNumber,//过磅单号 
			@RequestParam String client,//客户
			@RequestParam String netWeight,//净重
			@RequestParam String matter_type,//物料类型
			@RequestParam String materiel,//物料
			@RequestParam String wagonNumber,//车号
			@RequestParam String billNo,//通知单号单号
			@RequestParam String state,//状态
			@RequestParam Integer page,
			@RequestParam Integer pageSize
			){
		return splService.SalePoundList(start_time,end_time,shippingUnit,xsPoundNumber,client,netWeight,matter_type,materiel,wagonNumber,billNo,state,page,pageSize);//id
}
	@PostMapping("/SalePoundListExport")
	public Object[][] SalePoundListExport(
			@RequestParam String start_time,
			@RequestParam String end_time,
			@RequestParam String shippingUnit,//发货单位
			@RequestParam String xsPoundNumber,//过磅单号 
			@RequestParam String client,//客户
			@RequestParam String netWeight,//净重
			@RequestParam String matter_type,//物料类型
			@RequestParam String materiel,//物料
			@RequestParam String wagonNumber,//车号
			@RequestParam String billNo,//通知单号单号
			@RequestParam String state//状态
			){
		return splService.SalePoundListExport(start_time,end_time,shippingUnit,xsPoundNumber,client,netWeight,matter_type,materiel,wagonNumber,billNo,state);//id
}
	//新销售磅单列表导出
	@RequestMapping(value="SalePoundListExports",method=RequestMethod.GET)
	public void SalePoundListExports(
			@RequestParam String start_time,
			@RequestParam String end_time,
			@RequestParam String shippingUnit,//发货单位
			@RequestParam String xsPoundNumber,//过磅单号 
			@RequestParam String client,//客户
			@RequestParam String netWeight,//净重
			@RequestParam String matter_type,//物料类型
			@RequestParam String materiel,//物料
			@RequestParam String wagonNumber,//车号
			@RequestParam String billNo,//通知单号单号
			@RequestParam String state,
			HttpServletResponse response//状态
			){
		 splService.SalePoundListExports(start_time,end_time,shippingUnit,xsPoundNumber,client,netWeight,matter_type,materiel,wagonNumber,billNo,state,response);//id
}
	@PostMapping("/findOne")
	public ResultBean<List<Map<String,Object>>>findOne(
			@RequestParam String uuid
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error",splService.findOne(uuid));//id
}
}
